﻿@model ShoppingCartModel
@using Nop.Core
@using Nop.Core.Infrastructure
@using Nop.Web.Models.ShoppingCart;
@{
    var webHelper = EngineContext.Current.Resolve<IWebHelper>();
}
<div class="order-summary-content">
    @Html.Widget("order_summary_content_before")
    @Html.Partial("_OrderReviewData", Model.OrderReviewData)
    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
        <div class="alert alert-danger square-box">
            
                @for (int i = 0; i < Model.Warnings.Count; i++)
                {
                    <div>@Model.Warnings[i]</div>
                }
            
        </div>
        }
@*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <div class="table-responsive">
                <table class="cart table table-bordered">
                    <colgroup>
                        @if (Model.IsEditable)
                        {
                            <col width="1" />
                        }
                        @if (Model.ShowSku)
                        {
                            <col width="1" />
                        }
                        @if (Model.ShowProductImages)
                        {
                            <col width="1" />
                        }
                        <col />
                        <col width="1" />
                        <col width="1" />
                        <col width="1" />
                    </colgroup>
                    <thead>
                        <tr class="cart-header-row">
                            @if (Model.IsEditable)
                            {
                                <th>
                                    @T("ShoppingCart.Remove")
                                </th>
                            }
                            @if (Model.ShowSku)
                            {
                                <th>
                                    @T("ShoppingCart.SKU")
                                </th>
                            }
                            @if (Model.ShowProductImages)
                            {
                                <th class="picture"></th>
                            }
                            <th>
                                @T("ShoppingCart.Product(s)")
                            </th>
                            <th>
                                @T("ShoppingCart.UnitPrice")
                            </th>
                            <th>
                                @T("ShoppingCart.Quantity")
                            </th>
                            <th class="end">
                                @T("ShoppingCart.ItemTotal")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Items)
                        {
                            <tr class="cart-item-row">
                                @if (Model.IsEditable)
                                {
                                    <td class="remove-from-cart">
                                        <input type="checkbox" name="removefromcart" value="@(item.Id)" />
                                    </td>
                                }
                                @if (Model.ShowSku)
                                {
                                    <td class="sku nobr">
                                        @item.Sku
                                    </td>
                                }
                                @if (Model.ShowProductImages)
                                {
                                    <td class="product-picture">
                                        <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
                                    </td>
                                }
                                <td class="product">
                                    <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" class="product-name">@item.ProductName</a>
                                    @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                    {
                                        <div class="attributes">
                                            @Html.Raw(item.AttributeInfo)
                                        </div>
                                    }
                                    @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                    {
                                        <div class="recurring-info">
                                            @Html.Raw(item.RecurringInfo)
                                        </div>
                                    }
                                    @if (Model.IsEditable && item.AllowItemEditing)
                                    {
                                        var editCartItemUrl = Url.RouteUrl("Product", new {SeName = item.ProductSeName});
                                        editCartItemUrl = webHelper.ModifyQueryString(editCartItemUrl, "updatecartitemid=" + item.Id, null);
                                        <div class="edit-item">
                                            <a class="btn btn-default" href="@editCartItemUrl">@T("Common.Edit")</a>
                                        </div>
                                    }
                                    @if (item.Warnings.Count > 0)
                                    {
                                
                                        <div class="alert alert-danger square-box">
                                            @for (int i = 0; i < item.Warnings.Count; i++)
                                            {
                                                <div>@item.Warnings[i]</div>
                                            }
                                        </div>
                                
                                    }
                                </td>
                                <td class="unit-price nobr">
                                    <span class="product-unit-price">@item.UnitPrice</span>
                                </td>
                                <td class="qty nobr">
                                    @if (Model.IsEditable)
                                    {
                                        if (item.AllowedQuantities.Count > 0)
                                        {
                                            <select name="itemquantity@(item.Id)" class="form-control square-box">
                                                @foreach (var qty in item.AllowedQuantities)
                                                {
                                                    <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                                }
                                            </select>
                                        }
                                        else
                                        {
                                            <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="form-control square-box inheri-width" />
                                        }

                                    }
                                    else
                                    {
                                        <span>@item.Quantity</span>
                                    }
                                </td>
                                <td class="subtotal nobr end">
                                    <span class="product-subtotal">@item.SubTotal</span>
                                    @if (!String.IsNullOrEmpty(item.Discount))
                                    {
                                        <div class="discount">
                                            @T("ShoppingCart.ItemYouSave"): @item.Discount
                                        </div>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
                if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
        <div class="selected-checkout-attributes">
            @Html.Raw(Model.CheckoutAttributeInfo)
        </div>
                }
        <div class="buttons">
            @if (Model.IsEditable)
            {
                <div class="common-buttons">
                    <input type="submit" name="updatecart" value="@T("ShoppingCart.UpdateCart")" class="btn btn-default" />
                    <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" class="btn btn-default" />
                </div>
                @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
            }
        </div>
        <div class="cart-footer">
            @Html.Widget("order_summary_cart_footer")
            @if (Model.IsEditable)
            {
                if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                {
                <div>
                    <div class="min-amount-warning">
                        @Model.MinOrderSubtotalWarning
                    </div>
                </div>
                }
            }
            <div class="row">
                <div class="col-md-8">
                    <div class="cart-collaterals">
                        @if (Model.IsEditable)
                        {
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="deals">
                                        @Html.Partial("_DiscountBox", Model.DiscountBox)
                                        @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                                        @Html.Widget("order_summary_content_deals")
                                    </div>
                                </div>
                                
                                    @Html.Partial("EstimateShipping", Model.EstimateShipping)
                               
                            </div>
                        }
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="offer offer-default">
                        @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                        @if (Model.IsEditable)
                        {
                            if (Model.TermsOfServiceOnShoppingCartPage)
                            {
                                <div id="terms-of-service-warning-box" title="@T("Checkout.TermsOfService")" style="display:none;">
                                    <p>@T("Checkout.TermsOfService.PleaseAccept")</p>
                                </div><br/>
                                <div class="terms-of-service">
                                    <input id="termsofservice" type="checkbox" name="termsofservice" />
                                    @T("Checkout.TermsOfService.IAccept")
                                    <span class="read" onclick="javascript:OpenWindow('@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofUse" })', 450, 500, true)"><a>@T("Checkout.TermsOfService.Read")</a></span>
                                </div><br/>
                            }
                            <div class="checkout-buttons">
                                @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                                {
                                    <script type="text/javascript">
                                        $(document).ready(function () {
                                            $('#checkout').click(function () {
                                                //terms of service
                                                var termOfServiceOk = true;
                                                if ($('#termsofservice').length > 0) {
                                                    //terms of service element exists
                                                    if (!$('#termsofservice').is(':checked')) {
                                                        $("#terms-of-service-warning-box").dialog();
                                                        termOfServiceOk = false;
                                                    } else {
                                                        termOfServiceOk = true;
                                                    }
                                                }
                                                return termOfServiceOk;
                                            });
                                        });
                                    </script>
                                    <button type="submit" id="checkout" name="checkout" value="checkout" class="btn btn-default">
                                        <span>@T("Checkout.Button")</span>
                                    </button>
                                }
                            </div>
                            <div class="addon-buttons">
                                @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                                @Html.Partial("_ButtonPaymentMethod", Model)
                            </div>
                        }
                    </div>
                </div>
            </div>
        </div>
        if (Model.IsEditable)
        {
             @Html.Action("CrossSellProducts", "Product")
        }
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
    @Html.Widget("order_summary_content_after")
</div>
